package com.qk.management.controller;

import com.qk.common.Result;
import com.qk.dto.course.CourseDTO;
import com.qk.entity.Course;
import com.qk.management.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/courses")
public class CourseController {
    @Autowired
    private CourseService courseService;
    @GetMapping
    public Result list(CourseDTO courseDTO){
        return courseService.list(courseDTO);
    }
    @GetMapping("/{id}")
    public Result get(@PathVariable Integer id){
        Course course = courseService.get(id);
        return Result.success(course);
    }
    @GetMapping("/list")
    public Result selectAll(){
        List<Course> courses = courseService.selectAll();
        return Result.success(courses);
    }
    @PostMapping
    public Result add(@RequestBody Course course){
        courseService.add(course);
        return Result.success();
    }
    @PutMapping
    public Result updateById(@RequestBody Course course){
        courseService.updateById(course);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        courseService.delete(id);
        return Result.success();
    }
    @GetMapping("/subject/{subject}")
    public Result selectBySubject(@PathVariable Integer subject){
        List<Course> courses = courseService.selectBySubject(subject);
        return Result.success(courses);
    }

}
